import { request } from '../utils/request.js'
import store from '../store'
import { Toast, Jump } from '../utils/tools.js'
import md5 from 'js-md5'
import { balance, UserInfo } from '@/api/Users.js'



//转账
export async function Transfer(params) {
	try {
		// params.paypassword = md5(params.paypassword);
		let res = await request({
			url: '/Trade/Transfer',
			method: "post",
			params
		})
		if (res.success) {
			await balance()
		}
		return res
	} catch (e) {
		return false
	}
}

//提现申请
export async function WithdrawApply(params) {
	try {
		// params.paypassword = md5(params.paypassword);
		let res = await request({
			url: '/Trade/WithdrawApply',
			method: "post",
			params
		})
		if (res.success) {
			await balance()
		}
		return res
	} catch (e) {
		return false
	}
}


//提现申请记录
export async function GetWithdrawApply(params) {
	try {
		let res = await request({
			url: '/Trade/GetWithdrawApply',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}


//提现申请
export async function chainWithdrawApply(params) {
	try {
		// params.paypassword = md5(params.paypassword);
		let res = await request({
			url: '/Trade/chainWithdrawApply',
			method: "post",
			params
		})
		if (res.success) {
			await balance()
		}
		return res
	} catch (e) {
		return false
	}
}

//提现申请记录
export async function chainWithdrawPage(params) {
	try {
		let res = await request({
			url: '/Trade/chainWithdrawPage',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}

//资金记录
export async function GetUserBalanceRecord(params) {
	try {
		let res = await request({
			url: '/Trade/GetUserBalanceRecord',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}

//绑定编辑银行卡
export async function addEditBank(data) {
	try {
		let res = await request({
			url: '/Users/addEditBank',
			method: "post",
			data
		})
		if (res.success) {
			await UserInfo()
		}

		return res
	} catch (e) {
		return false
	}
}

//默认银行卡
export async function SetDef(params) {
	try {
		let res = await request({
			url: '/Trade/SetDef',
			method: "post",
			params
		})

		return res
	} catch (e) {
		return false
	}
}
 //删除
export async function Del(params) {
	try {
		let res = await request({
			url: '/Users/DelBank',
			method: "post",
			params
		})

		return res
	} catch (e) {
		return false
	}
}


//银行卡列表
export async function banklist() {
	try {
		const res = await request({
			url: '/Users/banklist',
			method: "post",
		})
		if(res.data){
			const a = {}
			res.data.forEach(item=>{
				a[item.id] = item
			})
			store.commit('user/SET_BANKCARD',a)
			store.commit('user/SET_BANKCARDList',res.data)
		}
		return res
	} catch (e) {
		return false
	}
}


export async function GetBalanceTotla(params) {
	try {
		let res = await request({
			url: '/Trade/GetBalanceTotla',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}

export async function creditdetal(params) {
	try {
		let res = await request({
			url: '/Trade/creditdetal',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}


export async function creditTotal(params) {
	try {
		let res = await request({
			url: '/Trade/creditTotal',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}



export async function creditDay(params) {
	try {
		let res = await request({
			url: '/trade/creditDay',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return false
	}
}





// 线下充值登记
export async function tbvRegister(params) {
	try {
		let res = await request({
			url: '/Trade/tbvRegister',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return []
	}
}

// 我的线下充值记录
export async function Getutb(params) {
	try {
		let res = await request({
			url: '/Trade/Getutb',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return []
	}
}




export async function buyVip(params) {
	try {
		let res = await request({
			url: '/Trade/buyVip',
			method: "post",
			params
		})
		return res
	} catch (e) {
		return []
	}
}



